define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'pms/pmsuser/index' + location.search,
                    edit_url: 'pms/pmsuser/edit',
                    table: 'pms_user',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormVisible: true,
                columns: [
                    [
                        {field: 'id', title: __('Id'), operate: false},
                        {field: 'realname', title: __('Realname'), operate: 'LIKE'},
                        {field: 'sname', title: __('Sname'), operate: 'LIKE'},
                        {field: 'pinyin', title: __('Pinyin'), operate: 'LIKE'},
                        {field: 'sex', title: __('Sex'), searchList: {"0":__('女'),"1":__('男')}, formatter: Table.api.formatter.label},
                        {field: 'person_no', title: __('Person_no'), operate: 'LIKE'},
                        {field: 'tel', title: __('Tel'), operate: 'LIKE'},
                        {field: 'check_in_count', title: __('Check_in_count'), operate: false},
                        {field: 'state', title: __('State'), searchList: {"0":__('正常'),"-1":__('已删除')}, formatter: Table.api.formatter.status},
                        {field: 'updatetime', title: __('Updatetime'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'last_editor_nickname', title: __('Last_editor'), operate: false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        edit: function () {
            var id = $('#c-id').val();
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'pms/pmsuser/get_user_order_list?ids=' + id,
                    table: 'pms_user',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                commonSearch: false,
                showToggle: false,
                showExport: false,
                showColumns:false,
                pagination: false,
                columns: [
                    [
                        {field: 'id', title: __('Id'), operate: false},
                        {field: 'order_no', title: __('订单号'), operate: 'LIKE'},
                        {field: 'source', title: __('来源')},
                        {field: 'check_in_time', title: __('入住时间'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'check_out_time', title: __('退房时间'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'days', title: __('天数'), operate:'BETWEEN'},
                        {field: 'room_info_id', title: __('房间'), formatter:function (value, row, index){
                            return '<span class="label label-primary">'+row['room_type_name']+'</span><br />' + row['room_no'] + '房';
                        }},
                        {field: 'order_status', title: __('订单状态'), searchList: {"0":__('已入住'),"1":__('已出院'),"-1":__('作废')}, formatter: Table.api.formatter.status},
                        {field: 'gmv', title: __('销售额'), operate:'BETWEEN'},
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);

            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});